package com.idanchuang.component.logback;

import ch.qos.logback.classic.PatternLayout;
import com.idanchuang.component.logback.converter.*;

/**
 * 添加自定义占位符
 * @author yjy
 */
public class CustomPatternLogbackLayout extends PatternLayout {

    static {
        defaultConverterMap.put("m", MaskMessageConverter.class.getName());
        defaultConverterMap.put("msg", MaskMessageConverter.class.getName());
        defaultConverterMap.put("message", MaskMessageConverter.class.getName());

        defaultConverterMap.put("F", FileOfCallerConverter.class.getName());
        defaultConverterMap.put("file", FileOfCallerConverter.class.getName());
        defaultConverterMap.put("L", LineOfCallerConverter.class.getName());
        defaultConverterMap.put("line", LineOfCallerConverter.class.getName());

        defaultConverterMap.put("M", MethodOfCallerConverter.class.getName());
        defaultConverterMap.put("method", MethodOfCallerConverter.class.getName());

        try {
            Class.forName("org.apache.servicecomb.pack.omega.context.OmegaContext");
            defaultConverterMap.put("tid", TxIdEnhancedTraceIdPatternConverter.class.getName());
        } catch (ClassNotFoundException e) {
            defaultConverterMap.put("tid", TraceIdPatternConverter.class.getName());
        }
        defaultConverterMap.put("appid", AppidPatternConverter.class.getName());
        defaultConverterMap.put("version", VersionPatternConverter.class.getName());
        defaultConverterMap.put("group", GroupPatternConverter.class.getName());
        defaultConverterMap.put("host", HostPatternConverter.class.getName());
        defaultConverterMap.put("port", PortPatternConverter.class.getName());
        defaultConverterMap.put("keyword", KeywordPatternConverter.class.getName());
        try {
            Class.forName("org.springframework.web.context.request.RequestContextHolder");
            Class.forName("javax.servlet.http.HttpServletRequest");
            defaultConverterMap.put("url", UrlPatternConverter.class.getName());
            defaultConverterMap.put("duration", DurationPatternConverter.class.getName());
        } catch (ClassNotFoundException e) {
            defaultConverterMap.put("url", DefaultPatternConverter.class.getName());
            defaultConverterMap.put("duration", DefaultPatternConverter.class.getName());
        }

    }
}
